#include("../../comm/ListHead.html")
<div class="layui-fluid layui-anim layui-anim-fadein">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="card-search SearchTable">
                    <p style="float:right">
                        <input type="text" id="task_id" placeholder="任务ID" class="table-search-text width80"/>
                        <input type="text" id="task_name" placeholder="任务名" class="table-search-text width200"/>
                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>
                    </p>
                    <div class="layui-tab layui-tab-brief">
                        <ul class="layui-tab-title" style="width: 300px;float:left">
                            <li class="layui-this"><i class="layui-icon layui-icon-date"></i> 定时任务列表</li>
                            <li lay-event="TurnLogList"><i class="layui-icon layui-icon-time"></i> 任务日志</li>
                        </ul>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSysTask">
                                <i class="layui-icon">&#xe608;</i> 添加定时任务
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSysTask">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSysTask">删除</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-9" lay-event="DoneSysTask">执行一次</button>
                        </div>
                    </script>
                    <script type="text/html" id="temp_action">
                        <div class="layui-btn-container" style="float:none">
                            {{- d.task_action }}
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">

    layui.use(['myTable', 'table', 'form', 'util', 'myTool', 'drawer'], function () {
        var $ = layui.$, myTable = layui.myTable, myTool = layui.myTool;
        /**
         * 表格
         */
        tableindex = layui.myTable.render({
            url: 'SysTaskListDataApi'
            , title: '定时任务列表', escape: false
            , where: {}
            , cols: [[
                {type: 'checkbox', width: 30, fixed: true}
                , {field: 'task_id', title: '任务ID', width: 70, sort: true, align: 'center'}
                , {field: 'status', title: '运行状态', width: 70, align: 'center', colorfield: 'status_color'}
                , {field: 'task_name', title: '任务名', width: 120}
                , {field: 'task_cron', title: '表达式', width: 100}
                , {field: 'task_class', title: '执行类', width: 300}
                , {field: 'last_done', title: '最后执行', width: 140, sort: true}
                , {field: 'task_desc', title: '备注'}
                , {field: 'is_auto_str', title: '加载', width: 40, align: 'center'}
                , {field: 'is_log_str', title: '日志', width: 40, align: 'center'}
                , {field: '', title: '操作', width: 120, align: 'center', templet: '#temp_action'}
            ]]
            , page: true, limit: 10
            , serviceSort: true, initSort: {field: 'task_id', type: 'desc'}
            , editField: {url: 'ModifySysTaskFieldApi', key: 'task_id'}
        });


        /**
         * 按钮事件
         */
        layui.util.event("lay-event", {
            DoSearch: function () {
                tableindex.reload({
                    where: {like: {task_id: $("#task_id").val(), task_name: $("#task_name").val()}}
                    , page: {curr: 1}
                });
            }
            , TurnLogList: function () {
                window.location.href = "SysTaskLogList";
            }
        });


        /**
         * 工具栏事件
         */
        layui.table.on('tool(table_1)', function (obj) {
            myTool.tool(this, obj, {
                StartTask: function (data) {
                    index = top.layer.confirm('你是否确认启动任务【' + data.task_id + '】', {icon: 3, title: '提示', offset: '150px'}, function (index2) {
                        myTool.postMsg("StartSysTaskApi", {
                            task_id: data.task_id
                        }, function () {
                            top.layer.close(index2);
                            tableindex.reload();
                        });
                    });
                }
                , StopTask: function (data) {
                    index = top.layer.confirm('你是否确认停止任务【' + data.task_id + '】', {icon: 3, title: '提示', offset: '150px'}, function (index2) {
                        myTool.postMsg("StopSysTaskApi", {
                            task_id: data.task_id
                        }, function () {
                            top.layer.close(index2);
                            tableindex.reload();
                        });
                    });
                }
            });
        });

        /**
         * 工具栏事件
         */
        layui.table.on('toolbar(table_1)', function (obj) {
            myTool.toolbar(this, obj, {
                AddSysTask: function () {
                    index = top.layer.open({
                        type: 2, offset: '60px', area: ['800px', '580px'], title: ['添加定时任务', 'font-size:15px;'],
                        content: ["systask/AddSysTask", 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditSysTask: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        if (data[0].run == 1) {//运行中不能修改
                            top.layer.alert("请先停止运行任务再修改");
                        } else {
                            index = top.layer.open({
                                type: 2, offset: '60px', area: ['800px', '580px'], title: ['修改定时任务[' + data[0].task_id + ']', 'font-size:15px;'],
                                content: ["systask/EditSysTask?task_id=" + data[0].task_id, 'no'],
                                end: function () {
                                    tableindex.reload({});
                                }
                            });
                        }
                    });
                }
                , DelSysTask: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        if (data[0].run == 1) {//运行中不能修改
                            top.layer.alert("请先停止运行任务再修改");
                        } else {
                            index = top.layer.confirm('你是否确认删除定时任务【' + data[0].task_id + '】', {icon: 3, title: '提示', offset: '150px'}, function (index2) {
                                myTool.postMsg("DelSysTaskApi", {
                                    task_id: data[0].task_id
                                }, function () {
                                    top.layer.close(index2);
                                    tableindex.reload();
                                });
                            });
                        }
                    });
                }
                , DoneSysTask: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.confirm('你是否确认现在就执行任务【' + data[0].task_id + '】', {icon: 3, title: '提示', offset: '150px'}, function (index2) {
                            myTool.postMsg("RunSysTaskApi", {
                                task_id: data[0].task_id
                            }, function () {
                                top.layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                    ''
                }
            });
        });
    });
</script>
#include("../../comm/Foot.html")